<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb20">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="primary"-->
      <!--          plain-->
      <!--          icon="el-icon-plus"-->
      <!--          size="mini"-->
      <!--          @click="handleAdd"-->
      <!--        >新建-->
      <!--        </el-button-->
      <!--        >-->
      <!--      </el-col>-->

      <el-col :span="1.5">
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="房间" prop="premisesAddress">
        <el-input
          v-model="queryParams.premisesAddress"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资金流向" prop="cooperationType">
        <el-select v-model="queryParams.cooperationType">
          <el-option
            v-for="item in capitalFlowMappings"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="list"
      ref="table"
    >
      <el-table-column
        label="房间"
        prop="premisesAddress"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="资金流向"
        prop="roomType"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <!--          <span v-if="scope.row.cooperationType === CAPITAL_FLOW.MERCHANT_NO"-->
          <!--          >{{ capitalFlowMapping[scope.row.cooperationType] }}</span>-->
          <!--          <span v-if="scope.row.cooperationType === CAPITAL_FLOW.PLATFORM_NO"-->
          <!--          >{{ capitalFlowMapping[scope.row.cooperationType] }}</span>-->

          <span>{{ capitalFlowMappingText(scope.row.cooperationType) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.cooperationType == 2"
            v-hasPermi="['bill:allocation:edit']"
          >编辑
          </el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <edit v-model="addDialog" :data="data" @success="getList"/>
  </div>
</template>

<script>
import {
  listRoom,
  getRoom,
  getStatistics,
  countHouseState,
  delRoom
} from '@/api/house/room'

import { listAllocation } from '@/api/bill/allocation'

import { CAPITAL_FLOW } from '@/views/sharingAccount/bill/constant'

import edit from '@/views/sharingAccount/bill/componets/edit'

export default {
  name: 'roomManage',
  dicts: ['dict_online_rental_type', 'dict_house_state', 'dict_house_nature'],
  components: {
    edit
  },
  data() {
    return {
      // 遮罩层
      //
      capitalFlowMapping: {
        '1': '商户号',
        '2': '分账平台'
      },
      capitalFlowMappings: [
        { value: '1', label: '商户号' },
        { value: '2', label: '分账平台' }
      ],
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      addDialog: false,
      //数据
      data: {},
      // 当前选择
      current: '0',
      // 日期范围
      dateRange: [],

      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        premisesAddress: undefined,
        roomNumber: undefined,
        houseNature: undefined,
        houseState: undefined,
        chargeType: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        roomNumber: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        roleSort: [
          { required: true, message: '角色顺序不能为空', trigger: 'blur' }
        ]
      },
      roomId: ''
    }
  },
  computed: {
    CAPITAL_FLOW() {
      return CAPITAL_FLOW
    },
    capitalFlowMappingText() {
      return (value) => {
        let obj = this.capitalFlowMappings.find(item => item.value === value)
        return obj ? obj.label : ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询房间列表 */
    getList() {
      this.loading = true
      this.queryParams.startTime = this.dateRange[0]
      this.queryParams.endTime = this.dateRange[1]
      listAllocation(this.queryParams).then(
        (response) => {
          this.list = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    // 取消按钮
    cancel() {
      this.addDialog = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.roomId = ''
      this.addDialog = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.roomId = row.houseId
      this.addDialog = true
      this.data = { ...row }
    }
  }
}
</script>
<style lang="scss" scoped>
.title {
  font-size: 14px;
  font-weight: 500;
  color: #666;
}

.total {
  font-size: 18px;
  font-weight: 500;
  color: #333;
  margin-top: 6px;
}

.left-border {
  border-left: 1px solid #999;
}

.right-border {
  border-right: 1px solid #999;
}

.info {
  padding: 10px 15px;
  margin: 15px 0;
  background: #e6f7ff;
  color: #1890ff;

  span {
    color: #565c5f;
  }

  .clear {
    margin-left: 20px;
    cursor: pointer;
  }
}
</style>
